﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VLUSM_DataAccess.Repositories
{
    public class HoSoDaNopRepository : GenericRepository<MainDataContainer>
    {
        public HoSoDaNopRepository(string connectionString) : base(connectionString, "MainData") { }
        public HoSoDaNopRepository(MainDataContainer context) : base(context) { }

        public HoSoDaNop GetSingleByID(int IDFilter)
        {
            var query = this.GetFirst<HoSoDaNop>(d => d.ID == IDFilter);
            return query;
        }

        public IEnumerable<HoSoDaNop> GetAll()
        {
            var query = this.GetAll<HoSoDaNop>();
            return query;
        }

        public IEnumerable<HoSoDaNop> GetAllByPhienBanGiaoID(int PhienBanGiaoIDFilter)
        {
            var query = this.Find<HoSoDaNop>(h => this.Any<PhienBanGiao>(p => p.ID == PhienBanGiaoIDFilter));
            return query;
        }

        public IEnumerable<HoSoDaNop> GetAllBySinhVienID(int SinhVienIDFilter)
        {
            var query = this.Find<HoSoDaNop>(h => this.Any<SinhVien>(p => p.ID == SinhVienIDFilter));
            return query;
        }

        public IEnumerable<HoSoDaNop> GetAllByLoaiHoSoID(int LoaiHoSoIDFilter)
        {
            var query = this.Find<HoSoDaNop>(h => this.Any<LoaiHoSo>(l => l.ID == LoaiHoSoIDFilter));
            return query;
        }

        public void Save(HoSoDaNop obj)
        {
            try
            {
                if (obj.ID != 0)
                {
                    this.Attach<HoSoDaNop>(obj);
                }
                else
                {
                    this.Add<HoSoDaNop>(obj);
                }
            }
            catch { }
        }

        public void Remove(HoSoDaNop obj)
        {
            this.Delete<HoSoDaNop>(obj);
        }

        public void Remove(int IDFilter)
        {
            var obj = this.GetSingleOrDefault<HoSoDaNop>(h => h.ID == IDFilter);
            this.Delete<HoSoDaNop>(obj);
        }
    }
}

